<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <?= $show_code; ?>
        <title><?php echo $this->config->item('title_page'); ?></title>
    </head>
    <script>
        $(document).ready(function() {

            $('#btnBackPage').click(function() {
                parent.history.back();
                return false;
            });

            var lastIndex = 0;
            $("#add_file_upload").click(function() {
                if (lastIndex < 0) {
                    lastIndex = 0;
                }
                if (lastIndex < 5) {
                    $("#div_upload").append("<div class='form-group' id='divUpload" + lastIndex + "'><input type='file' name='uploadFile" + lastIndex + "' style='margin-left:20px'></div>");
                    $("#count_upload").attr('value', $('[type="file"]').length);
                    lastIndex = lastIndex + 1;

                }
            });

            $("#remove_file_upload").click(function() {
                if (lastIndex === 5) {
                    lastIndex = 4;
                }

                if (lastIndex >= 0) {
                    $("#divUpload" + (lastIndex)).remove();
                    lastIndex = lastIndex - 1;
                }
            });

            //Event Combobox Model
            $('#cmbBrand').change(function() {
                $.ajax({
                    type: "POST",
                    url: "<?php echo base_url(); ?>truck/add_truck/get_model",
                    data: {id: $('#cmbBrand').val()},
                    dataType: "json",
                    success: function(data) {
                        $("#cmbModel").find("option").remove();
                        if (data.length > 0) {
                            var opt = $('<option />');
                            opt.val("");
                            opt.text(data.list_model[""]);
                            $('#cmbModel').append(opt);
                            $.each(data.list_model, function(key, val) {
                                if (key !== "") {
                                    var opt = $('<option />');
                                    opt.val(key);
                                    opt.text(val);
                                    $('#cmbModel').append(opt);
                                }
                            });
                        }
                    }
                });
            });
        });
    </script>
    <body>
        <div class="panel panel-default body-contain">
            <div class="panel-heading"><span class="icon-g-truck"></span>
                <strong> การจัดการรถบรรทุก (Truck Management)</strong>
            </div>
            <div class="panel-body">
                <?php $this->load->view('contains/menu_module_bar'); ?>
                <div class="panel panel-default">
                    <div class="panel-heading"><span class="glyphicon glyphicon-file"></span>
                        <strong> เพิ่มข้อมูลรถบรรทุก</strong>
                    </div>
                    <?php echo form_open_multipart('truck/add_truck/validate', 'class="form-horizontal"  method="post"') ?>
                    <input type="hidden" id="count_upload" name="count_upload" value=""/>
                    <div class="panel-body">
                        <div class="pull-left col-xs-12 col-md-8">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">เลขทะเบียน</label>
                                <div class="col-sm-9">
                                    <?= $txt_license_plate; ?>
                                    <?= $err_license_plate; ?>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">ยี่ห้อ</label>
                                <div class="col-sm-5">
                                    <?= $cmb_brand; ?>
                                    <?= $err_brand; ?>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">รุ่น</label>
                                <div class="col-sm-5">
                                    <?= $cmb_model; ?>
                                    <?= $err_model; ?>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">หมายเลขเครื่อง</label>
                                <div class="col-sm-9">
                                    <?= $txt_moter_code; ?>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">หมายเลขไมล์</label>
                                <div class="col-sm-9">
                                    <?= $txt_mile_number; ?>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">ชื่อผู้ขับ</label>
                                <div class="col-sm-9">
                                    <?= $cmb_driver_name; ?>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-6">
                                    <button type="submit" class="btn btn-primary">บันทึกข้อมูล</button>
                                    <button id="btnBackPage" type="button" class="btn btn-default">ย้อนกลับ</button>
                                </div>
                            </div>
                            </form>
                        </div>
                        <div class="pull-left col-xs-6 col-md-4">
                            <div class="panel panel-default">
                                <div class="panel-heading"><span class="glyphicon glyphicon-picture"></span>
                                    <strong> อัพโหลดภาพถ่าย</strong>
                                    <div class="pull-right">
                                        <button type="button" class="btn btn-default btn-sm" style="margin-top: -5px" id="remove_file_upload">
                                            <span class="glyphicon glyphicon-minus"></span>
                                        </button>
                                        <button type="button" class="btn btn-primary btn-sm" style="margin-top: -5px;margin-right: -10px" id="add_file_upload">
                                            <span class="glyphicon glyphicon-plus"></span>
                                        </button>
                                    </div>
                                </div>
                                <div class="panel-body" id="div_upload">

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <?php echo form_close(); ?>
            </div>
        </div>
    </body>
</html>
